<template>
  <el-dialog
    title="查看凭证"
    width="428px"
    :visible.sync="visible"
    :close-on-click-modal="true"
    :close-on-press-escape="true"
    :show-close="true"
    :append-to-body="true"
    :before-close="beforeClose"
  >
    <el-form>
      <div class="dialog-box">
        <div class="dialog-box-item">
          <div class="el-form-item__label" style="width: 100%;text-align: left;">凭证截图</div>
          <div class="pic-box" v-if="imgList.length">
            <el-image v-for="(item, index) in imgList"
                      :key="'pic' + index"
                      :src="item + '?v=' + new Date().getTime()"
                      :preview-src-list="imgList"
            >
              <div slot="error" class="image-slot">暂无图片</div>
            </el-image>
          </div>
          <div class="pic-box" v-else>
            <el-image>
              <div slot="error" class="image-slot">暂无图片</div>
            </el-image>
          </div>
          <div class="el-form-item__label" style="width: 100%;text-align: left;">凭证视频</div>
          <div class="pic-box">
            <video class="video" controls v-if="videoUrl" :src="videoUrl + '?v=' + new Date().getTime()">您的浏览器不支持视频播放</video>
            <div class="no-video" v-else>暂无视频</div>
          </div>
        </div>
      </div>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="closeOrder">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
  import {mapActions} from 'vuex'
  import util from '@/libs/util.js'

  export default {
    name: 'audit-info',
    props: {
      visible: {
        type: Boolean,
        default: false
      },
      id: {
        type: String,
        default: ''
      }
    },
    data() {
      return {
        status: null,
        auditForm: {
          orderId: '',
          status: null,
          remark: ''
        },
        imgList: [],
        videoUrl: null
      }
    },
    mounted () {
      this.queryInfo()
    },
    methods: {
      ...mapActions('d2admin/pm.audit', [
        'auditInfo',
        'auditSubmit'
      ]),
      // 查询历史列表
      queryInfo () {
        this.auditInfo({
          orderId: this.id
        }).then(res => {
          res.orderItems.forEach(item => {
            if (item.type === 0) {
              this.imgList.push(item.url)
            } else if (item.type === 1) {
              this.videoUrl = item.url
            }
          })

          this.status = res.status
        })
      },
      // 关闭之前
      beforeClose () {
        this.$emit('beforeClose', false)
      },
      // 关闭订单
      closeOrder () {
        this.$emit('closeOrder', false)
      }
    }
  }
</script>

<style lang="scss">
  .dialog-box {
    display: flex;
    flex-direction: row;

    .dialog-box-item {
      flex: 1;
      padding: 10px;
    }
    .pic-box {
      width: 366px;
      display: flex;
      flex-direction: row;
      flex-wrap: wrap;
      .el-image {
        overflow: hidden;
        background-color: #fff;
        border: 1px solid #c0ccda;
        border-radius: 6px;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        width: 114px;
        height: 114px;
        margin: 0 8px 8px 0;
        display: inline-block;
        text-align: center;
        line-height: 114px;
        color: #c5c5c5;
      }
      .no-video {
        width: 366px;
        height: 160px;
        background-color: #fff;
        border: 1px solid #c0ccda;
        border-radius: 6px;
        text-align: center;
        line-height: 160px;
        color: #c5c5c5;
      }
    }
    .video {
      width: 366px;
      height: 160px;
    }
  }
</style>
